package com.company.service.impl;

import com.company.entity.user;
import com.company.service.StartService;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Xiaoshuo implements StartService {
    Scanner sc=new Scanner(System.in);
        List list1=new ArrayList();
    public Xiaoshuo() {
        user b2 = new user();
        b2.setXu(1);
        b2.setNames("雪山飞狐");
        b2.setZuozhe("金庸");
        b2.setJianjie("长篇小说");
        list1.add(b2);
        user b12 = new user();
        b12.setXu(2);
        b12.setNames("顾夏金玉");
        b12.setZuozhe("顾夏");
        b12.setJianjie("短篇小说");
        list1.add(b12);
    }

    @Override
    public List ex(List list) {
        for (;;) {
            System.out.println("--------------------");
            System.out.println("0.退出登录");
            System.out.println("1.言情");
            System.out.println("2.武侠");
            System.out.println("--------------------");
            System.out.println("请选择：");
            switch (sc.nextInt()) {
                case 0:
                    System.exit(0);
                    break;
                case 1:
                    System.out.println("-----言情小说列表开始-----");
                    System.out.println("序号\t\t名称\t\t作者\t\t简介");
                    for (int i = 0; i < list1.size(); i++) {
                        user bb = (user) list1.get(i);
                        System.out.println(bb.getXu() + "\t\t" + bb.getNames() + "\t" + bb.getZuozhe() + "\t" + bb.getJianjie());
                    }
                    System.out.println("-----言情小说列表结束-----");
                    System.out.println("0.返回上一级菜单");
                    System.out.println("-1.上传小说");
                    System.out.println("请选择：：");
                    int fan = sc.nextInt();
                    switch (fan) {
                        case 0:
                            continue;
                        default:
                            if (fan==-1) {
                                user b22 = new user();
                                System.out.println("输入小说序号：");
                                b22.setXu(sc.nextInt());
                                System.out.println("输入小说名称：");
                                b22.setNames(sc.next());
                                System.out.println("输入小说作者：");
                                b22.setZuozhe(sc.next());
                                System.out.println("输入小说简介：");
                                b22.setJianjie(sc.next());
                                System.out.println("请输入上传的路径：");
                                String ss=sc.next();
                                File file = new File(ss);
                                try {
                                    FileInputStream inputStream = new FileInputStream(file);
                                } catch (FileNotFoundException e) {
                                    System.out.println("未找到此文件路径");
                                    break;
                                }
                                list1.add(b22);
                            }else{
                                System.out.println("没有该序号");
                            }
                            break;
                    }
                    break;
                case 2:
                    System.out.println("-----武侠小说列表开始-----");
                    System.out.println("序号\t\t名称\t\t作者\t\t简介");
                    break;
            }
        }

    }


}
